package com.oauth.components.client.ui.footer;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class FooterUI extends Composite {

	private static FooterUiBinder uiBinder = GWT.create(FooterUiBinder.class);

	interface FooterUiBinder extends UiBinder<Widget, FooterUI> {
	}

	private static final FooterConstant constants = (FooterConstant) GWT
			.create(FooterConstant.class);

	@UiField
	Label copyrightLabel;

	@UiField
	HorizontalPanel linksPanel;

	@UiField
	HorizontalPanel footerPanel;

	@UiField
	HorizontalPanel copyrightPanel;

	@UiField
	Anchor aboutUs;

	@UiField
	Anchor developers;

	@UiField
	Anchor followUs;

	@UiField
	Anchor feedback;

	AboutUsDialog dialogBox;
	DevelopersDialog developersBox;
	FeedbackDialog feedbackBox;

	public FooterUI() {
		initWidget(uiBinder.createAndBindUi(this));
		dialogBox = new AboutUsDialog();
		developersBox = new DevelopersDialog();
		feedbackBox = new FeedbackDialog();
		copyrightLabel.setText(constants.copyrightText());
		footerPanel.setCellHorizontalAlignment(copyrightPanel, VerticalPanel.ALIGN_LEFT);
		footerPanel.setCellHorizontalAlignment(linksPanel, VerticalPanel.ALIGN_RIGHT);
	}

	@UiHandler("aboutUs")
	public void onClick(ClickEvent e) {
		dialogBox.center();
	}

	@UiHandler("developers")
	public void onDevelopersClick(ClickEvent e) {
		developersBox.center();
	}

	@UiHandler("feedback")
	public void onFeedbackClick(ClickEvent e) {
		feedbackBox.center();
	}

	@UiHandler("followUs")
	public void onFollowUsClick(ClickEvent e) {
		Window.open(constants.rssLink(), "Follow us", null);
	}
}
